/**
 * Created by hcadmin on 16/4/8.
 */

define([
    "jquery",
    "IO",
    "bootbox",



    //"text!/js/biz/keb/activity/definebt.html"
], function ($, IO) {



    //
    $(function(){
        //参数设定
        var year1=1;
        var year2=2;
        var year3=3;

        $("#btnSave1").click(function(){
            if ($("#form1").valid(this,'内容出错')==false){
                return false;
            }
            parameter(year1);
        })
        $("#btnSave2").click(function(){
            parameter(year2);
        })
        $("#btnSave3").click(function(){
            parameter(year3);
        })

    });


    function parameter(year_id){

        var id;
        if(year_id==1){
            id=0;
        }
        else if(year_id==2)
        {
            id=1;
        }
        else {
            id=2;
        }

        var sales_profit=$(".sale").eq(id).val()==""?"0":$(".sale").eq(id).val();
        var market_share=$(".market").eq(id).val()==""?"0":$(".market").eq(id).val();
        var development=$(".produces").eq(id).val()==""?"0":$(".produces").eq(id).val();
        var team_capacity=$(".team").eq(id).val()==""?"0":$(".team").eq(id).val();
        var capital_pool=$(".money").eq(id).val()==""?"0":$(".money").eq(id).val();
        var activity_mid=$("#activity_mid_hidden").val();

        if(!isNaN(sales_profit)&&!isNaN(market_share)&&!isNaN(development)&&!isNaN(team_capacity)&&!isNaN(capital_pool)){
            var params={};
            params.sales_profit=sales_profit;
            params.market_share=market_share;
            params.development=development;
            params.team_capacity=team_capacity;
            params.capital_pool=capital_pool;
            params.activity_mid=activity_mid;
            params.year_id=year_id;

            if(activity_mid!=""){
                if(sales_profit!=""&&market_share!=""&&development!=""&&team_capacity!=""&&capital_pool!=""){

                    IO.post("/shapan/api/parameter",params,function(d){
                        if(d.code==0){
                            alert("提交成功");
                        }
                    })
                }
                else{
                    alert("请填写完整的参数!!");
                }
            }
            else {
                alert("请创建活动");
            }
        }
        else {
            alert('请输入正确格式');
        }

    }

});